<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //类 进行封装
        class Stack {
            constructor() {
                this.item = [];
            }

            //push()
            push(element) {
                this.item.push(element);
            }

            //pop()
            pop() {
                return this.item.pop();
            }

            //peek()
            peek() {
                return this.item[this.item.length - 1];
            }

            //size()
            size() {
                return this.item.length;
            }
            isEmpty() {
                return this.size() === 0;
            }
            toString() {
                return this.item.toString();
            }
        }

        // const stack = new Stack();
        // stack.push("cn");
        // stack.push("us");
        // stack.push("jp");
        // console.log(stack.toString());
        // console.log(stack.pop());
        // console.log(stack.toString());
        // console.log(stack.peek());
        // console.log(stack.size());
        // console.log(stack.isEmpty());


        function decimal2Binary(decNumber) {
            const stack = new Stack();
            let rem;
            let number = decNumber;
            while (number > 0) {
                rem = Math.floor(number / 2);
                rem = Math.floor(number % 2);
                stack.push(rem);
            }
            while (!stack.isEmpty()) {
                binaryString += stack.pop().toString();
            }
            return binaryString;
        }
        let number = 40;
        console.log(decimal2Binary(number));

        console.log("math.floor:" + Math.floor(number % 2));
        console.log("no " + number % 2);
        console.log("no " + number % 2);

        console.log("math.floor:" + Math.floor(number / 2));
        console.log("no " + number / 2);
    </script>
</body>

</html>